<?php

class ActionManage extends BaseAction
{
    public function run()
    {
        $iRumorId = Yii::app()->request->getParam('rumor_id');
        
        if ( $iRumorId )
        {
            $oRumor = Rumor::model()->findByPk($iRumorId);
        }
        else
        {
            $oRumor               = new Rumor();
            $oRumor->rumor_active = 1;
            $oRumor->rumor_cdate  = time();
        }
        
        if ( Yii::app()->request->getIsPostRequest() )
        {
            $oRumor->setAttributesFromRequest('Rumor');
            
            if ( $oRumor->save() )
            {
                if ( $oRumor->isNewRecord )
                {
                    Yii::app()->user->setFlash('rumor_saved_success', 'Слух успешно создан.');
                }
                else
                {
                    Yii::app()->user->setFlash('rumor_saved_success', 'Слух успешно сохранен.');
                }
            
                Yii::app()->controller->redirect(Yii::app()->controller->createUrl('/admin/rumors'));
            }
        }
        
        $this->template->oRumor = $oRumor;
    }
}